<%@ page import="java.util.List" %>
<%@ page import="cn.acmoj.oj.bean.Problem" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>${applicationScope.ojName}</title>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/amazeui.min.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/amazeui.flat.min.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/amazeui.page.css"/>
    <style>
        .main {
            width: 60%;
            margin: 0 auto;
        }

        .title {
            font-size: 2em;
            background: #FFF;
            border-bottom: solid 1px #CCCCCC;
            padding: 10px;
        }

        th {
            text-align: center;
            font-size: 15px;
        }

        .id {
            width: 110px;
            text-align: center;
        }

        .rate,
        .level,
        .num {
            text-align: center;
            width: 80px;
        }

        .two .t_name,
        .name {
            float: left;
        }

        .two .t_type,
        .type {
            float: right;
        }

        #page ul {
            margin-left: 0;
            margin-right: 0;
        }
    </style>
</head>

<body>

<jsp:include page="/heard.html" flush="true"/>

<div class="title">
    <div class="main">
        题库
    </div>
</div>

<div class="main">
    <div class="am-panel-bd">
        <form class="am-form am-form-inline" action="#" method="get">
            <div class="am-input-group">
                <input type="text" class="am-form-field" placeholder="题目编号" name="pid">
                <span class="am-input-group-btn">
                    <button class="am-btn am-btn-default" type="submit">Go</button>
                </span>
            </div>
            <div class="am-input-group">
                <input type="text" class="am-form-field" name="search" title="search">
                <span class="am-input-group-btn">
            <button class="am-btn am-btn-default" type="submit">搜索</button>
            </span>
            </div>
        </form>
    </div>
    <table class="am-table am-table-striped am-table-hover am-table-bordered">
        <thead>
        <tr>
            <th>编号</th>
            <th class="two">
                <div class="t_name">
                    名称
                </div>
                <div class="t_type">
                    标签
                </div>
            </th>
            <th>难度</th>
            <th>通过人数</th>
            <th>正确率</th>
        </tr>
        </thead>
        <tbody>
        <%
            List<Problem> list = (List<Problem>) request.getAttribute("list");
            List<Integer> l = (List<Integer>) request.getAttribute("list_s");
            for (int i = 0; i < list.size(); i++) {
        %>
        <tr>
            <td class="id">
                <%
                    if (session.getAttribute("user") != null) {
                        if (l.get(i) == 0) {
                            out.print("<span class=\"am-badge am-round\"> </span>");
                        } else if (l.get(i) == 1) {
                            out.print("<span class=\"am-badge am-badge-success am-round am-icon-check\"> </span>");
                        } else {
                            out.print("<span class=\"am-badge am-badge-danger am-round am-icon-exclamation\"> </span>");
                        }
                    }
                %>
                <a href="${pageContext.request.contextPath}/problem.html?pid=<%=list.get(i).getProblem_id()%>"><%=list.get(i).getProblem_id()%>
                </a>
            </td>
            <td>
                <div class="name">
                    <a href="${pageContext.request.contextPath}/problem.html?pid=<%=list.get(i).getProblem_id()%>"><%=list.get(i).getTitle()%>
                    </a>
                </div>
                <div class="type">
                    <span class="am-badge am-round"><%=list.get(i).getSource()%></span>
                </div>
            </td>
            <td class="level">Lv.<%=list.get(i).getDifficulty()%>
            </td>
            <td class="num"><%=list.get(i).getAccepted()%>
            </td>
            <td class="rate">
                <%
                    double a = list.get(i).getAccepted() * 10000;
                    a /= list.get(i).getSubmit();
                    a = (int) a;
                    out.print(a / 100);
                %>%
            </td>
        </tr>
        <%
            }
        %>
        </tbody>
    </table>
    <div id="page"></div>
</div>

<jsp:include page="/foot.html" flush="true"/>

<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/amazeui.min.js"></script>
<script src="${pageContext.request.contextPath}/js/amazeui.page.js"></script>
<script>
    $(function () {
        $('.problemset').addClass('am-active');
        var page = window.location.search.match(/page=(\d+)/);
        $("#page").page({
            pages: ${requestScope.count},
            first: "首页", //设置false则不显示，默认为false
            last: "尾页", //设置false则不显示，默认为false
            prev: '<', //若不显示，设置false即可，默认为上一页
            next: '>', //若不显示，设置false即可，默认为下一页
//            groups: 3, //连续显示分页数
            curr: page ? page[1] : 1, //当前页码
            jump: "problemset.html?page=%page%"
            //jump: function(context) {
            //		$("#tips3").html("共" + context.option.pages + "页，当前第" + context.option.curr + "页");
            //}
        });
    })
</script>
</body>

</html>